//
//  ZLMainController.swift
//  新浪微博
//
//  Created by 朱玉龙 on 9/22/16.
//  Copyright © 2016 朱玉龙. All rights reserved.
//

import UIKit

class ZLMainController: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setValue(ZLTabBar(), forKey: "tabBar")
        
        addViewControllers()
        
        (tabBar as! ZLTabBar).composeButton.addTarget(self, action: #selector(buttonClick(btn:)), for: .touchUpInside)
        
        
    }

    @objc private func buttonClick(btn: UIButton) {
    
        
        let toolbar = ZLPlusToolbar(frame: self.view.bounds)
        toolbar.show(controller: self)
       
        
    }

    
    //增加button按钮
  fileprivate  func addViewControllers() {
        
        
        addViewController(ZLHomeController(), title: "首页", imageName: "tabbar_home")
        
        addViewController(ZLMessageController(), title: "消息", imageName: "tabbar_message_center")
        
        addViewController(ZLDiscoverController(), title: "发现", imageName: "tabbar_discover")
        
        addViewController(ZLProfileController(), title: "我", imageName: "tabbar_profile")
        
    }
    
    fileprivate func addViewController(_ controller: UIViewController ,title:String,imageName:String ) {
        
        controller.title = title
        
        controller.tabBarItem.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -5)
        
        controller.tabBarItem.image = UIImage(named: imageName)
        
        controller.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orange], for: .selected)
        
        let nv = ZLBaseNavigationController(rootViewController: controller)
        
        addChildViewController(nv)
        
    }
    
}
